package dao

import (
	influxdb2 "github.com/influxdata/influxdb-client-go/v2"
	"log"
	"time"
)

type InfluxClient struct {
	org    string
	bucket string
	client influxdb2.Client
}

type InfluxRecord struct {
	Time        time.Time
	Tags        map[string]string
	Fields      map[string]interface{}
	Measurement string
}

func (client *InfluxClient) InsertRecord(record InfluxRecord) {
	log.Printf("insert record %+v", record)
	writer := client.client.WriteAPI(client.org, client.bucket)
	p := influxdb2.NewPoint(record.Measurement,
		record.Tags,
		record.Fields,
		record.Time)
	writer.WritePoint(p)
}
